package com.zhouh.golden.security.code.sms;

import com.zhouh.golden.security.config.RabbitMqConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhouheng
 */
@Component
public class DefaultSmsSender implements SmsCodeSender {

    @Value("${golden.security.code.sms.expire-in}")
    private long expireIn;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void send(String mobile, String code) {
        // 1.手机号码校验
        // 2. 调用短信服务发送短信
        Map<String,String> map = new HashMap<>();
        map.put("checkCode", code);
        map.put("mobile",mobile);

        //在控制台显示一份【方便测试】
        System.out.println("手机号：" + mobile + "的短信验证码为：" + code + "，有效时间：" + expireIn + " 秒");

        rabbitTemplate.convertAndSend(RabbitMqConfig.queueName, map);
    }
}
